class R {
  constructor(code = 0, message = '', type = 'success', data = '') {
    this.code = code;
    this.message = message;
    this.type = type;
    this.data = data;
  }

  static ok(data, message = '') {
    return new R(1, message, 'success', data);
  }

  static msg(message) {
    return new R(1, message, 'success');
  }

  static err(code, message) {
    return new R(code, message, 'error');
  }

  static errMsg(message) {
    return new R(0, message, 'error');
  }

  static errCode(code, message) {
    return new R(code, message, 'error');
  }

  static errData( message, data) {
    return new R(0, message, 'error', data);
  }

  static errType(type, message) {
    return new R(0, message, type);
  }

  static errTypeData(type, message, data) {
    return new R(0, message, type, data);
  }

  static errTypeCode(type, code, message) {
    return new R(code, message, type);
  }
}
global.R = R